#pragma once
#include <cstddef>
#include <stdexcept>
#include <iostream>

class MemoryPool {
public:
    explicit MemoryPool(size_t blockSize);
    ~MemoryPool();
    
    void* allocate();
    void deallocate(void* block);
    
    void printStatus() const;
    
    // 禁止拷贝和移动
    MemoryPool(const MemoryPool&) = delete;
    MemoryPool& operator=(const MemoryPool&) = delete;

private:
    struct BlockHeader {
        BlockHeader* next;
    };

    const size_t m_blockSize;
    const size_t m_totalBlocks;
    size_t m_freeBlocks;
    char* m_memory;
    BlockHeader* m_freeList;
    
    void initializeFreeList();
};